package com.litt.saap.system.dao;

import com.litt.core.dao.GenericHibernateDao;
import com.litt.saap.system.po.UserGroup;

/**
 * .
 * 
 * <pre><b>描述：</b>
 *    
 * </pre>
 * 
 * <pre><b>修改记录：</b>
 *    
 * </pre>
 * 
 * @author <a href="mailto:littcai@hotmail.com">蔡源</a>
 * @since 2013-8-29
 * @version 1.0
 */
public class UserGroupDao extends GenericHibernateDao<UserGroup, Integer> {
  
  /**
   * Gets the max code.
   *
   * @param tenantId the tenant id
   * @param parentId the parent id
   * @return the max code
   */
  public long getParentCode(int id)
  {
	  if(id==0){
		  return 0;
	  }
    return super.uniqueResult("select code from UserGroup where id=?", new Object[]{id}, Long.class);
  }

  
  /**
   * Gets the max code.
   *
   * @param tenantId the tenant id
   * @param parentId the parent id
   * @return the max code
   */
  public long getMaxCode(int tenantId, int parentId)
  {
    Object ret = super.uniqueResult("select max(code) from UserGroup where tenantId=? and parentId=?", new Object[]{tenantId, parentId});
    if(ret==null)
      return 0L;
    else {
      return (Long)ret;
    }
  }
  
  public int getSubCount(int id)
  {
    return super.count("select count(id) from UserGroup where parentId=?", new Object[]{id});
  }

}
